﻿@using Xms.Schema.Extensions;
@using Xms.RibbonButton.Abstractions;
@using Xms.QueryView.Abstractions;

@model Xms.Web.Models.EntityGridModel
@{
    Layout = null;
}
@{
    this.app.PageTitle = Model.QueryView.Name;
}
@{
    var mainEntity = Model.EntityList.First();
    var jsLibs = new List<string>();
    var resources = new List<Guid>();
    if (Model.IsShowButtons && Model.RibbonButtons.NotEmpty())
    {
        foreach (var btn in Model.RibbonButtons)
        {
            if (btn.JsLibrary.IsNotEmpty())
            {
                if (btn.JsLibrary.StartsWith("$webresource:"))
                {
                    var wsId = Guid.Parse(btn.JsLibrary.Replace("$webresource:", ""));
                    if (!resources.Contains(wsId))
                    {
                        resources.Add(wsId);
                    }
                }
                else if (!jsLibs.Contains(btn.JsLibrary))
                {
                    jsLibs.Add(btn.JsLibrary);
                }
            }
        }
    }
    var hasNonePermissionField = Model.NonePermissionFields.NotEmpty();
}
<div>

    <div id="queryview-section">
        @{
            if (Model.IsShowButtons)
            {
                <div class="container-fluid margin-bottom" style="border:1px #eee dashed;position:relative;">
                    @{
                        if (Model.RibbonButtons.NotEmpty())
                        {
                            var headButtons = Model.RibbonButtons.Where(n => n.ShowArea == RibbonButtonArea.ListHead).ToList();
                            foreach (var btn in headButtons)
                            {
                                <a class="@btn.CssClass@(btn.IsVisibled ? "" : " hide")" href="javascript:void(0)" onclick="@btn.JsAction" @(btn.IsEnabled ? "" : " disabled")><span class="@btn.Icon"></span> @btn.Label</a>
                            }
                        }
                    }
                    @*<a class="btn btn-link btn-sm" href="javascript:void(0)" onclick="Xms.Data.Export('@Model.QueryViewId')" target="_blank"><span class="glyphicon glyphicon-export"></span> @app.T["export"]</a>*@
                    <div class="btn-group hide">
                        <a class="btn btn-link btn-sm dropdown-toggle" data-toggle="dropdown">
                            <span class="glyphicon glyphicon-import"></span> @app.T["export"] <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu" role="menu">
                            <li>
                                <a class="btn btn-link btn-sm" href="javascript:void(0)" onclick="Xms.Data.Export('@Model.QueryViewId', 0, filters)" target="_blank"><span class="glyphicon glyphicon-chevron-right"></span> @app.T["export"]</a>
                            </li>
                            <li>
                                <a class="btn btn-link btn-sm" href="javascript:void(0)" onclick="Xms.Data.Export('@Model.QueryViewId', 1, filters)" target="_blank"><span class="glyphicon glyphicon-chevron-right"></span> @app.T["export_includeprimarykey"]</a>
                            </li>
                        </ul>
                    </div>
                    <a class="btn btn-link btn-sm hide" href="#" onclick="Xms.Web.OpenDialog('/entity/import?entityid=@Model.EntityId','')"><span class="glyphicon glyphicon-import"></span> 导入数据</a>
                </div>

            }
        }
        <div class="margin-bottom" style="padding-top:10px;">
            <div class="container-fluid  form-inline">
                <div class="custom-form-group row">
                    @*<h5><strong>@Model.QueryView.Name - 视图</strong></h5>*@
                    <div class="custom-input-ctrl col-xs-3  col-sm-3" style="margin-top:6px; min-width:175px;">
                        @*@if (Model.IsEnabledViewSelector)
                            {
                                <a id="viewDropdown" class="dropdown-toggle btn btn-info btn-sm viewDropdown-btn" data-toggle="dropdown" title="@Model.QueryView.Name" href="#">
                                    <span class="glyphicon glyphicon-th"></span> <span class="selecter-label">@Model.QueryView.Name</span> <span class="caret"></span>
                                </a>
                                <ul class="dropdown-menu" id="viewSelector" data-value="@Model.QueryView.QueryViewId">
                                    @foreach (var item in Model.QueryViews)
                                    {
                                        @:
                                        <li><a href="javascript:void(0)" data-value="@item.QueryViewId" title="@item.Name">@item.Name</a></li>
                                    }
                                </ul>
                            }
                            else
                            {
                                <label class="custom-input-inline col-sm-6" id="viewSelector" title="@Model.QueryView.Name" data-value="@Model.QueryView.QueryViewId" style="text-align:left;">@Model.QueryView.Name</label>
                            }
                            <div class="btn-group list-align-style" id="listAlignStyle" role="group" aria-label="切换显示方式">
                                <span type="button" id="listAlignTop" data-type="top" class="btn "><em class="glyphicon glyphicon-object-align-top"></em></span>
                                <span type="button" id="listAlignLeft" data-type="left" class="btn active"><em class="glyphicon glyphicon-object-align-left"></em></span>
                            </div>*@
                    </div>
                    <div class="xms-form-dropdown col-xs-4 col-sm-4 xms-formDropDown kanban-filter hide" style="width:150px;">
                        <div class="btn-group">
                            <div class="btn btn-default btn-sm xms-formDownInput " style="width:130px;border-radius:4px;" title="@app.T["filter"]">
                                <span class="glyphicon glyphicon-filter"></span>
                                请选择字段
                            </div><span class="caret" style="position: absolute;right: 15px;top: 50%;z-index:9;"></span>
                        </div>
                        <div class="xms-formDropDown-List container-fluid in" id="kanbanSearch" style="width:250px; padding:10px;">
                            <div class="custom-input-ctrl col-sm-10">
                                <div class="row seacher-row xms-formDropDown-Item" data-name="" data-type="picklist">
                                    <label class="col-sm-6 text-right" for="">统计字段</label>
                                    <div class="col-sm-6">
                                        <div class="form-group">
                                            <select class="form-control" id="aggregateField">
                                                <option></option>
                                                @foreach (var attr in Model.AttributeList.Where(n => n.TypeIsInt() || n.TypeIsFloat() || n.TypeIsDecimal() || n.TypeIsMoney()))
                                                {
                                                    <option value="@attr.Name">@attr.LocalizedName</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="row seacher-row xms-formDropDown-Item" data-name="" data-type="picklist">
                                    <label class="col-sm-6 text-right" for="">分组字段</label>
                                    <div class="col-sm-6">
                                        <div class="form-group">
                                            <select class="form-control" id="groupField">
                                                <option></option>
                                                @foreach (var attr in Model.AttributeList.Where(n => n.TypeIsPickList() || n.TypeIsStatus()))
                                                {
                                                    <option value="@attr.Name">@attr.LocalizedName</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                @*<div class="row seacher-row xms-formDropDown-Item" data-name="" data-type="picklist">
                                        <label class="col-sm-4 text-right" for=""></label>
                                        <div class="col-sm-8">
                                            <div class="form-group">
                                                <select class="form-control" id="countField">
                                                    <option value="10">10</option>
                                                    <option value="20">20</option>
                                                    <option value="50">50</option>
                                                    <option value="100">100</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>*@
                            </div>
                            <div class="row text-center">
                                <div class="col-sm-12">
                                    <div class="btn btn-default btn-sm" onclick="page_common_formSearcher.closeKanban()">@app.T["cancel"]</div>
                                    <div class="btn btn-info btn-sm" onclick="page_common_formSearcher.searchKanban(); page_common_formSearcher.closeKanban();">@app.T["dialog_ok"]</div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="custom-input-ctrl col-xs-8  col-sm-8 custom-input-change date-filter-section pull-right" style="min-width:455px;">
                        <div class="custom-btn-group" style="min-width:356px;">
                            <div class="btn-group btn-group-sm pull-right" id="dayfilters">
                                <button type="button" data-day="@DateTime.Now.ToString("yyyy-MM-dd")" style="border-radius:0; margin-left:-1px;" class="btn btn-default" onclick="DayQuery(this)">@app.T["filter_date_today"]</button>
                                <button type="button" data-day="@DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")" class="btn btn-default" onclick="DayQuery(this)">@app.T["filter_date_last7day"]</button>
                                <button type="button" data-day="@DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd")" class="btn btn-default" onclick="DayQuery(this)">@app.T["filter_date_lastmonth"]</button>
                                <button type="button" data-day="@DateTime.Now.AddMonths(-3).ToString("yyyy-MM-dd")" class="btn btn-default" onclick="DayQuery(this)">@app.T["filter_date_last3month"]</button>
                                <button type="button" data-day="@DateTime.Now.AddMonths(-6).ToString("yyyy-MM-dd")" class="btn btn-default" onclick="DayQuery(this)">@app.T["filter_date_last6month"]</button>
                                <button type="button" data-day="@DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd")" class="btn btn-default" onclick="DayQuery(this)">@app.T["filter_date_lastyear"]</button>
                                <button type="button" title="刷新" class="btn btn-default" onclick="rebind()"><span class="glyphicon glyphicon-refresh"></span></button>
                            </div>
                        </div>
                        <div class="custom-input-ctrl custom-input-hide filter-section pull-right">
                            <form action="@("/"+app.OrganizationUniqueName)/entity/gridview" id="searchForm" method="post" class="form-inline">
                                @Html.HiddenFor(x => x.EntityId)
                                @Html.HiddenFor(x => x.QueryViewId)
                                @Html.HiddenFor(x => x.SortBy)
                                @Html.HiddenFor(x => x.SortDirection)
                                <input type="hidden" value="1" name="page" />
                                <input type="hidden" name="QField" id="QField" value="@Model.QField" />
                                <div class="xms-form-dropdown row xms-formDropDown">
                                    <div class="col-sm-12">
                                        <div class="btn-group">
                                            <div class="btn btn-default btn-sm xms-formDownInput " style="width:85px;border-radius:4px 0 0 4px;" title="@app.T["filter"]"><span class="glyphicon glyphicon-filter"></span> @app.T["filter"]</div><span class="caret" style="position: absolute;right: 10px;top: 50%;z-index:9;"></span>
                                        </div>
                                        <div class="xms-formDropDown-List container-fluid" id="searchFormSearch" style="width:336px; padding:10px;">
                                            <div style="max-height:350px;overflow-x:hidden;overflow:auto;">
                                                @foreach (var cell in Model.Grid.Rows[0].Cells)
                                                {
                                                    var isrelated = cell.Name.IndexOf(".") > 0;
                                                    var k = isrelated ? cell.Name.Split('.')[1] : cell.Name.ToLower();
                                                    var label = cell.Label;
                                                    Xms.Schema.Domain.Attribute attr = null;
                                                    if (!isrelated)
                                                    {
                                                        attr = Model.AttributeList.Find(n => n.EntityId == mainEntity.EntityId && n.Name.IsCaseInsensitiveEqual(k));
                                                        //label = attr.LocalizedName;
                                                    }
                                                    else
                                                    {
                                                        attr = Model.AttributeList.Find(n => n.EntityName.IsCaseInsensitiveEqual(cell.EntityName) && n.Name.IsCaseInsensitiveEqual(k));
                                                        //显示字段+引用字段
                                                        //var relationship = Model.RelationShipList.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Name.Split('.')[0]));
                                                        //label = attr.LocalizedName + "(" + relationship.ReferencingAttributeLocalizedName + ")";
                                                    }
                                                    if (attr == null) { continue; }
                                                    var nonePf = hasNonePermissionField ? Model.NonePermissionFields.Find(n => n.AttributeId == attr.AttributeId) : null;
                                                    if (nonePf != null) { continue; }
                                                    var ctrlId = isrelated ? cell.Name.Replace(".", "_") : cell.Name;
                                                    <div class="row seacher-row xms-formDropDown-Item" data-name="@cell.Name" data-type="@attr.AttributeTypeName.ToLower()">
                                                        <label class="col-sm-4 text-right" for="@cell.Name">@label</label>
                                                        <div class="col-sm-8">
                                                            @if (attr.TypeIsDateTime())
                                                            {
                                                                <div class="form-group">
                                                                    <input type="text" style="width:88px;" id="@ctrlId" class="form-control colinput input-sm datepicker" data-type="@attr.AttributeTypeName.ToLower()" autocomplete="off" name="@cell.Name" />
                                                                    <span style="width:10px;">-</span>
                                                                    <input type="text" style="width:87px;" autocomplete="off" class="form-control colinput input-sm datepicker" name="@cell.Name" data-type="@attr.AttributeTypeName.ToLower()" />
                                                                </div>
                                                            }
                                                            else if (attr.TypeIsPickList() || attr.TypeIsBit() || attr.TypeIsStatus() || attr.TypeIsState())
                                                            {
                                                                var itemStr = (attr.TypeIsPickList() || attr.TypeIsStatus()) ? attr.OptionSet.Items.SerializeToJson() : attr.PickLists.SerializeToJson();
                                                                <input type="text" id="@ctrlId" class="form-control colinput input-sm picklist" data-type="@attr.AttributeTypeName.ToLower()" data-name="@attr.Name" name="@cell.Name" data-items="@Html.UrlEncoder.Encode(itemStr)" />
                                                            }
                                                            else if (attr.TypeIsLookUp() || attr.TypeIsCustomer() || attr.TypeIsOwner() || attr.TypeIsPrimaryKey())
                                                            {
                                                                <div class="input-group input-group-sm">
                                                                    <input type="text" id="@ctrlId" data-type="lookup" data-entityid="@attr.ReferencedEntityId" data-referencedentityid="@attr.ReferencedEntityId" name="@cell.Name" class="form-control colinput lookup searchLookup" />
                                                                    <span class="input-group-btn">
                                                                        <button type="button" name="clearBtn" class="btn btn-default ctrl-del" title="find" style="border-radius:0;"><span class="glyphicon glyphicon-remove-sign"></span></button>
                                                                        <button type="button" name="lookupBtn" class="btn btn-default ctrl-search" title="find" style="border-top-left-radius: 0;border-bottom-left-radius: 0;"><span class="glyphicon glyphicon-search"></span></button>
                                                                    </span>
                                                                </div>
                                                            }
                                                            else if (attr.TypeIsInt() || attr.TypeIsFloat() || attr.TypeIsDecimal() || attr.TypeIsMoney())
                                                            {
                                                                <div class="form-group">
                                                                    <input type="text" style="width:80px;" id="@ctrlId" class="form-control colinput input-sm" data-type="@attr.AttributeTypeName.ToLower()" style="width:90px;" name="@cell.Name" value="" />
                                                                    <span style="width:10px;">-</span>
                                                                    <input type="text" style="width:80px;" class="form-control colinput input-sm" name="@cell.Name" value="" data-type="@attr.AttributeTypeName.ToLower()" />
                                                                </div>
                                                            }
                                                            else
                                                            {
                                                                <input type="text" id="@ctrlId" class="form-control colinput input-sm" name="@cell.Name" data-type="@attr.AttributeTypeName.ToLower()" value="" />
                                                            }
                                                        </div>
                                                    </div>
                                                }
                                            </div>
                                            <div class="row text-center">
                                                <div class="col-sm-12">
                                                    <div class="btn btn-default btn-sm event-bind" data-eventname="page_common_formSearcher.closeSearchC">@app.T["cancel"]</div>
                                                    <div class="btn btn-default btn-sm event-bind" data-eventname="page_common_formSearcher.clearSearchFiler">@app.T["clear"]</div>
                                                    <div class="btn btn-info btn-sm event-bind" id="searchFilterListBtn" data-eventname="page_common_formSearcher.closeSearchForm">@app.T["dialog_ok"]</div>
                                                    <button type="reset" name="resetBtn" class="hide"></button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div id="kanbanview" class="hide"></div>
        <div id="xms-gridview-section" class="xms-gridview-section  ">
            <div class="xms-table-navtree" id="xms-table-navtree">
            </div>
            <div class="pos_re ">
                @{
                    var btnStr = "";
                    if (Model.IsShowButtons && Model.RibbonButtons.NotEmpty())
                    {
                        var rowButtons = Model.RibbonButtons.Where(n => n.ShowArea == RibbonButtonArea.ListRow).ToList();
                        foreach (var btn in rowButtons)
                        {
                            btnStr += "<li><a class=\"" + btn.CssClass + " datagrid-inline-btns\" href=\"javascript: void(0)\" onclick=\"" + btn.JsAction + "\"><span class=\"" + btn.Icon + "\"></span> " + btn.Label + "</a></li>";
                        }
                    }
                }
                @*<div class="xms-table-section printArea" id="xms-table-section">
                    <div class="data-grid-box" style="margin-right:40px;" id="datatable">
                        <div class="datagrid-view" id="dataGridView"></div>
                    </div>
                    <div class="hide" id="fozon-wrap">
                        <table class="table table-hover table-striped table-condensed" id="fozon-table"></table>
                    </div>
                    <div class="panel panel-default tableReWidth hide" id="tableReWidth" style="min-height:350px; position:relative;">

                        <table class="table table-hover table-striped table-condensed" data-pageurl="@app.Url" data-refresh="rebind()" data-ajax="true" data-ajaxcontainer="gridview" data-ajaxcallback="ajaxgrid_reset()" data-sortby="@Model.SortBy.ToLower()" data-sortdirection="@Model.SortDirection" data-enabledfilter="@(Model.IsEnabledFastSearch.ToString().ToLower())">*@
                @*<thead>
                        <tr>
                            <th width="25" class="tableHeaderItem" data-width="25" style="width:25px"><input type="checkbox" name="checkall" /></th>
                            @if (btnStr.IsNotEmpty())
                            {
                                <th width="100" class="tableHeaderItem" data-width="50" style="width:50px"><a style="height: 20px;padding: 1%;cursor:default">@app.T["operation"]</a></th>
                            }
                            @{
                                var thWidth = 0;
                                foreach (var cell in Model.Grid.Rows[0].Cells)
                                {
                                    var isrelated = cell.Name.IndexOf(".") > 0;
                                    var k = isrelated ? cell.Name.Split('.')[1] : cell.Name.ToLower();
                                    var label = cell.Label;
                                    var relationentityid = "";
                                    thWidth += cell.Width;
                                    Xms.Schema.Domain.Attribute attr = null;
                                    var sortName = cell.Name;
                                    <input type="hidden" id="tableHeaderWidth" style="display:none;" value="@thWidth" />
                                    if (!isrelated)
                                    {
                                        attr = Model.AttributeList.Find(n => n.EntityId == mainEntity.EntityId && n.Name.IsCaseInsensitiveEqual(k));
                                        //label = attr.LocalizedName;
                                    }
                                    else
                                    {
                                        attr = Model.AttributeList.Find(n => n.EntityName.IsCaseInsensitiveEqual(cell.EntityName) && n.Name.IsCaseInsensitiveEqual(k));
                                        //显示字段+引用字段
                                        //var relationship = Model.RelationShipList.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Name.Split('.')[0]));
                                        //label = attr.LocalizedName + "(" + relationship.ReferencingAttributeLocalizedName + ")";
                                        //relationentityid = attr.ReferencedEntityId.ToString();
                                    }
                                    if (attr == null) { continue; }
                                    if (attr.TypeIsLookUp())
                                    {
                                        sortName += "Name";
                                    }
                                    var nonePf = hasNonePermissionField ? Model.NonePermissionFields.Find(n => n.AttributeId == attr.AttributeId) : null;
                                    if (nonePf != null)
                                    {
                                        <th class="tableHeaderItem" data-label="@label" data-width="@cell.Width" data-type="@attr.AttributeTypeName" style="width:@(cell.Width+"px")">
                                            <span class="glyphicon glyphicon-lock"></span> <span class="text-muted">@label</span>
                                        </th>
                                    }
                                    else
                                    {
                                        <th class="tableHeaderItem" data-width="@cell.Width" data-referencedentityid="@relationentityid" data-name="@sortName.ToLower()" style="width:@(cell.Width+"px")" data-label="@label" data-type="@attr.AttributeTypeName">
                                        </th>
                                    }
                                }

                            }
                        </tr>
                    </thead>
                    <tbody>
                        @{
                            var primaryKey = Model.AttributeList.Find(n => n.EntityId == mainEntity.EntityId && n.TypeIsPrimaryKey());
                            var primaryField = Model.AttributeList.Find(n => n.EntityId == mainEntity.EntityId && n.IsPrimaryField == true);
                            var hasRowCommand = Model.Grid.RowCommand.NotEmpty();
                        }
                        @foreach (var item in Model.Items)
                        {
                            var lines = (item as IDictionary<string, object>).ToList();
                            //行事件
                            string rowBgColor = "";
                            if (hasRowCommand)
                            {
                                foreach (var rowCmd in Model.Grid.RowCommand)
                                {
                                    if (rowCmd.ActionType == Xms.QueryView.Abstractions.Component.RowCommandActionType.SetRowBackground)
                                    {
                                        var rowFlag = rowCmd.IsTrue(lines, Model.AttributeList);

                                        if (rowFlag)
                                        {
                                            rowBgColor = (rowCmd.Action as Xms.QueryView.Abstractions.Component.SetRowBackgroundAction).Color;
                                            break;
                                        }
                                    }
                                }
                            }
                            var id = lines.Find(n => n.Key.IsCaseInsensitiveEqual(primaryKey.Name)).Value;
                            <tr data-dbclick="entityIframe('show',ORG_SERVERURL + '/entity/create?entityid=@mainEntity.EntityId&formid=@Model.TargetFormId&recordid=@id')" style="@(rowBgColor.IsNotEmpty()?"background:"+rowBgColor:"")">
                                <td><input type="checkbox" name="recordid" value="@id" /></td>
                                @if (btnStr.IsNotEmpty())
                                {
                                    <td class="visble gridvview-btnlist">
                                        <div class="btn-group" style="height:20px;width:100%;">
                                            <div class="btn btn-link dropdown-toggle btn-prevent" data-toggle="dropdown" aria-expanded="false" style="height: 100%;width:100%;line-height:0.5;text-align:left;padding: 6px 0px;">
                                                <span class="caret" style="top:-3px;"></span>
                                            </div>
                                            <ul class="dropdown-menu" role="menu" style="right:0;left:inherit;min-width: 100%;z-index: 9;">
                                                @Html.Raw(btnStr)
                                            </ul>
                                        </div>
                                    </td>
                                }
                                @foreach (var cell in Model.Grid.Rows[0].Cells)
                                {
                                    var columnName = cell.Name.ToLower();
                                    var isrelated = columnName.IndexOf(".") > 0;
                                    var attrName = isrelated ? columnName.Split('.')[1] : columnName;
                                    Xms.Schema.Domain.Attribute attr = null;
                                    if (isrelated)
                                    {
                                        attr = Model.AttributeList.Find(n => n.EntityName.IsCaseInsensitiveEqual(cell.EntityName) && n.Name.IsCaseInsensitiveEqual(attrName));
                                    }
                                    else
                                    {
                                        attr = Model.AttributeList.Find(n => n.EntityId == mainEntity.EntityId && n.Name.IsCaseInsensitiveEqual(attrName));
                                    }
                                    if (attr == null)
                                    {
                                        continue;
                                    }
                                    if (attr != null && (attr.TypeIsPrimaryKey() || attr.TypeIsLookUp() || attr.TypeIsOwner()))
                                    {
                                        columnName = attr.TypeIsPrimaryKey() ? primaryField.Name : columnName += "Name";
                                        var value = lines.Find(n => n.Key.IsCaseInsensitiveEqual(columnName)).Value;
                                        var recordid = lines.Find(n => n.Key.IsCaseInsensitiveEqual(cell.Name)).Value;
                                        <td>
                                            <div class="gridview-table-cell">
                                                @if (attr.DisplayStyle == "link")
                                                {
                                                    <a href="edit?entityid=@attr.ReferencedEntityId&recordid=@recordid" target="_blank" title="@value">@value</a>
                                                }
                                                else
                                                {
                                                    @value
                                                }
                                            </div>
                                        </td>
                                    }
                                    else if (attr.TypeIsPickList() || attr.TypeIsBit() || attr.TypeIsState() || attr.TypeIsStatus())
                                    {
                                        columnName += "Name";
                                        var value = lines.Find(n => n.Key.IsCaseInsensitiveEqual(columnName)).Value;
                                        <td> <div class="gridview-table-cell" title="@value">@value</div> </td>
                                    }
                                    else
                                    {
                                        var value = lines.Find(n => n.Key.IsCaseInsensitiveEqual(columnName)).Value;
                                        if (value != null && (attr.TypeIsDecimal()
                                                        || attr.TypeIsFloat()))
                                        {
                                            value = string.Format("{0:N" + attr.Precision + "}", value);
                                        }
                                        else if (value != null && attr.TypeIsMoney())
                                        {
                                            value = string.Format("￥{0:N" + attr.Precision + "}", value);
                                        }
                                        else if (value != null && attr.TypeIsDateTime())
                                        {
                                            if (attr.DataFormat.IsCaseInsensitiveEqual("yyyy/MM/dd"))
                                            {
                                                value = string.Format("{0:d}", value);
                                            }
                                            else
                                            {
                                                value = string.Format("{0:G}", value);
                                            }
                                        }
                                        else if (attr.IsPrimaryField)
                                        {
                                            value = string.Format("<a href=\"edit?entityid={0}&formid={1}&recordid={2}\" target=\"_blank\">{3}</a>", mainEntity.EntityId, Model.TargetFormId, id, value);
                                        }
                                        else if (attr.TypeIsNvarchar())
                                        {
                                            if (attr.DataFormat == "url" && value != null && value.ToString().IsNotEmpty())
                                            {
                                                value = string.Format("<a href=\"{0}\" title=\"新窗口打开\" target=\"_blank\"><span class=\"glyphicon glyphicon-share-alt\"></span></a>", value);
                                            }
                                        }
                                        <td><div class="gridview-table-cell @attr.AttributeTypeName.ToLower()">@Html.Raw(value)</div></td>
                                    }
                                }

                                @if (Model.IsShowButtons && rowButtons.NotEmpty())
                                    {
                                        <td>
                                            @foreach (var btn in rowButtons)
                                            {
                                           <a class="@btn.CssClass " href="javascript: void(0)" onclick="@btn.JsAction"><span class="@btn.Icon"></span>@btn.Label</a>
                                            }
                                        </td>
                                    }
                            </tr>
                        }
                    </tbody>*@
                @*@if (Model.AggregateFields.NotEmpty() && Model.AggregationData != null)
                            {
                                var dd = Model.AggregationData as IDictionary<string, object>;
                                <tfoot>
                                    <tr>
                                        <td></td>
                                        @if (btnStr.IsNotEmpty())
                                        {
                                            <td></td>
                                        }
                                        @foreach (var c in Model.Grid.Rows[0].Cells)
                                        {
                                            var aggf = Model.AggregateFields.Find(n => n.AttributeName.IsCaseInsensitiveEqual(c.Name));
                                            <td class="@(aggf != null ? "money" : "")">
                                                <strong class="agg-type-wrap"><span class="agg-type-name text-muted" data-name="@(c.Name)"></span><span class="agginfo-value" data-name="@(c.Name)">@(aggf != null ? dd[c.Name.ToLower()] : "")</span></strong>
                                            </td>
                                        }
                                    </tr>
                                </tfoot>
                            }
                        </table>
                    </div>
                    <input type="hidden" id="AggregateFields" value="@Model.AggregateFields.SerializeToJson()" />*@
                <div class="panel-footer hide">
                    <div class="row">
                        <div class="col-sm-4">
                            @(app.T["pagination_label"].Replace("{page}", Model.Page.ToString()).Replace("{totalpages}", Model.TotalPages.ToString()).Replace("{totalitems}", Model.TotalItems.ToString()))
                        </div>
                        <div id="page-selection" class="col-sm-8" data-total="@Model.TotalPages" data-page="@Model.Page"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@if (Model.IsShowButtons && Model.RibbonButtons.NotEmpty() && Model.RibbonButtons.Exists(x => x.ShowArea == RibbonButtonArea.ListRow))
{
    <div id="gridviewItemBtnstmpl" class="hide"><ul class="btn-list">@(btnStr)</ul></div>
}
@if (Model.IsShowChart == true)
{
    <div class="xms-fixed-slider clearfix">
        <div class="fl">
            <div class="xms-slider-ctrl " style="position:relative;z-index:100; cursor: pointer;"><img src="/content/images/chartsidelite.png" /></div>
        </div>
        <div class="fl">
            <div class="menu-wrap menu-md menu-right" style="margin-top: -136px;margin-right:50px;background:#fff;">
                <div class="tableResize-item tableResize-ctrl" style="position: absolute; height: 400px; right: 296px; width: 10px;" id="drag"></div>
                <div class="xms-slider-right" style="">
                    <div class="xms-slider-header">
                        <div class="btn-toolbar" role="toolbar" aria-label="">
                            <div class="btn-group" role="button" aria-label="" title="@app.T["chart"]"><em id="listchartWinBtn" class="glyphicon glyphicon-resize-horizontal"></em></div>
                            <div class="btn-group" role="group" aria-label=""></div>
                            <div class="btn-group" role="group" aria-label=""></div>
                        </div>
                        <div class="col-sm-12 row" style="padding: 0; margin: 0;">
                            <select id="ChartList" class="form-control"></select>
                        </div>
                    </div>
                    @*<div class="col-sm-12 row" style="padding: 0; margin: 0;">
                            <div class="silder-right-crumb hide">
                            </div>
                        </div>*@
                    <div class="xms-slider-content" style="margin-top:0px;" id="viewCharts">
                    </div>
                    <div class="xms-slider-footer">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="tools-modal" id="groupsInserModal">
        <div class="tools-modal-dialog">
            <div class="tools-modal-content">
                <div class="tools-modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span class="m-close-btn" aria-hidden="true" onclick="$(this).parents('.tools-modal').removeClass('active')">×</span>
                        <span class="sr-only">Close</span>
                    </button>
                    <h4 class="tools-modal-title"><span class="glyphicon glyphicon-th"></span> 向下钻取</h4>
                </div>
                <div class="tools-modal-body">
                    <div class="form-group">
                        <div class="row">
                            <div class="col-sm-4"><label>字段</label></div>
                            <div class="col-sm-8"><select class="groups-attributes tools-modal-control" id="groupsAttributes"></select></div>
                        </div>
                    </div>
                </div>
                <div class="tools-modal-footer">
                    <button type="button" class="btn btn-primary m-accept-btn btn-xs" id="groupsAttributesBtn">钻取</button>
                </div>
            </div>
        </div>
    </div>

}
<script>Xms.Page.PageContext.EntityId = '@Model.EntityId.Value'; Xms.Page.PageContext.QueryId = '@Model.QueryViewId.Value'; Xms.Page.PageContext.Scope = 'query'; Xms.Page.PageContext.TargetFormId = @(Model.TargetFormId.HasValue ? "'"+Model.TargetFormId.Value+"'" : "null");</script>
@foreach (var item in jsLibs)
{
    <script type="text/javascript" src="@item" charset="UTF-8"></script>
}
@if (resources.Count > 0)
{
    <script type="text/javascript" src="@("/"+app.OrganizationUniqueName)/api/webresource?ids=@(string.Join(",", resources))" charset="UTF-8"></script>
}
<div id="layoutConfig" class="hide" type="text/html">@Model.QueryView.LayoutConfig.ToLower()</div>
<script>
        /*
         *页面相关数据,必须暴露到全局
         */
        var page_Common_Info = {
            queryId: '@Model.QueryViewId',
            entityId:'@Model.EntityId.Value',
            queryName:'@Model.QueryView.Name',
            breadcrumb_url: '@app.UrlReferrer',
            breadcrumb_preName: '@Model.EntityList[0].LocalizedName',
            isviewselector: '@Model.IsEnabledViewSelector',
            isshowchart:'@Model.IsShowChart'
        }
        var layoutconfig = $('#layoutConfig').html();
        var layoutconfigObj = JSON.parse(layoutconfig);
      //  console.log('layoutconfigObj',layoutconfigObj)
</script>
<script src="~/content/js/common/charts.js?v=@app.PlatformSettings.VersionNumber"></script>
<script src="~/content/js/common/formsearcher.js?v=@app.PlatformSettings.VersionNumber"></script>

<script src="~/content/js/pages/entity.gridview.js?v=@app.PlatformSettings.VersionNumber"></script>
<script>
        //pageWrap_Gridview.init();

        $(function () {

        });
</script>
</div>